package com.ahcfl.controller;


import com.ahcfl.dto.PageBean;
import com.ahcfl.dto.ResponseWrap;
import com.ahcfl.pojo.Student;
import com.ahcfl.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping("/findAllStudentNames")
    public ResponseWrap findAllStudentNames(){

        List<String> namesList = studentService.findAllStudentNames();
        ResponseWrap responseWrap = new ResponseWrap(namesList);
        return responseWrap;
    }



    @RequestMapping("/addStudent")
    public ResponseWrap addStudent(String stuName){

        studentService.addStudent(stuName);

        return new ResponseWrap(true);
    }



    @RequestMapping("/findAllStudents")
    public ResponseWrap findAllStudents(int pageNum,int pageSize,String name){

        PageBean<Student> pageBean = studentService.findAllStudents(pageNum,pageSize,name);

        return new  ResponseWrap(pageBean);
    }

    @RequestMapping("/updateScore")
    public ResponseWrap updateScore(int id,@RequestParam("stuScore") int score){


        studentService.updateStudentScoreById(id,score);

        return new ResponseWrap(true);
    }

}
